const install = () => {
  uni.$u.http.interceptor.request = config => {
    config.header['server'] = true
    config.header['Device-Id'] = 'qewjrp-23134iurpqu9r0-2'
    // config.header['User-Agent'] =
    //   'Mozilla/5.0 (Linux; Android 15; V2359A; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/123.0.6312.118 Mobile Safari/537.36 VivoBrowser/23.6.0.1'
    config.header['Platform'] = 'ios'
    config.header['Accept'] = 'application/json'
    config.header['Content-Type'] = 'application/json'
    let token = uni.vk.vuex.get('$user.userInfo.token')
    if (token) {
      config.header['ba-user-token'] = token
    }
    return config
  }
  uni.$u.http.interceptor.response = res => {
    // if (res.code === 1) {
    //   return res
    // }
    // if (res.code === 401) {
    //   uni.vk.alert(res.msg, e => {
    //     uni.vk.navigateToLogin('')
    //   })
    //   return false
    // }
    // uni.vk.alert(res.msg)
    //  code  ==  303  未登录

    if (res.code == 303) {
      uni.vk.alert(res.msg, e => {
        uni.vk.navigateToLogin('')
      })
      return false
    }
    if (res.code == 401) {
      vk.alert(res.msg)
    }

    return res
  }
}
export default install
